package 装箱问题;

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int V = in.nextInt();
        int n = in.nextInt();
        int[] f = new int[V + 1];
        for (int i = 1; i <= n; i++) {
            int v = in.nextInt();
            for (int j = V; j >= v; j--) {
                f[j] = Math.max(f[j], f[j - v] + v);
            }
        }
        System.out.println(V - f[V]);
    }
}